package com.situ.lession1226.api;

import com.situ.lession1226.model.Review;
import com.situ.lession1226.service.ReviewService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

//对每个电影下面的评论进行展示和增加
@RestController
@RequestMapping(value = "/api/v1/review", produces = "application/json;charset=utf-8")
public class ReviewApi {
    private ReviewService reviewService;

    public ReviewApi(ReviewService reviewService) {
        this.reviewService = reviewService;
    }

    @GetMapping("/get")
    public Map<String,Object> get(Integer id){
        List <Review> review=reviewService.findAll(id);

        if (review == null) {
            return Map.of("success", false);
        } else {
            return Map.of("success",true,"review",review);
        }

    }
    @PostMapping("/post")
    public Map<String, Object> post(Review review){
        boolean success = reviewService.save(review);
        return Map.of("success", success);
    }
}
